home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 16 / AMIGAplus Sonderheft 16 (1998)(ICP)(DE)[!].iso / pd / anwendungen / ispell-3.1.18src / ispell.h < prev    next >
C/C++ Source or Header  |  1995-09-21  |  24KB  |  649 lines

  1. /*
  2.  * $Id: ispell.h 1.67  1995/01/03  19:24:12  geoff Exp $
  3.  */
  4.  
  5. /*
  6.  * Copyright 1992, 1993, Geoff Kuenning, Granada Hills, CA
  7.  * All rights reserved.
  8.  *
  9.  * Redistribution and use in source and binary forms, with or without
  10.  * modification, are permitted provided that the following conditions
  11.  * are met:
  12.  *
  13.  * 1. Redistributions of source code must retain the above copyright
  14.  *    notice, this list of conditions and the following disclaimer.
  15.  * 2. Redistributions in binary form must reproduce the above copyright
  16.  *    notice, this list of conditions and the following disclaimer in the
  17.  *    documentation and/or other materials provided with the distribution.
  18.  * 3. All modifications to the source code must be clearly marked as
  19.  *    such.  Binary redistributions based on modified source code
  20.  *    must be clearly marked as modified versions in the documentation
  21.  *    and/or other materials provided with the distribution.
  22.  * 4. All advertising materials mentioning features or use of this software
  23.  *    must display the following acknowledgment:
  24.  *      This product includes software developed by Geoff Kuenning and
  25.  *      other unpaid contributors.
  26.  * 5. The name of Geoff Kuenning may not be used to endorse or promote
  27.  *    products derived from this software without specific prior
  28.  *    written permission.
  29.  *
  30.  * THIS SOFTWARE IS PROVIDED BY GEOFF KUENNING AND CONTRIBUTORS ``AS IS'' AND
  31.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  32.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  33.  * ARE DISCLAIMED.  IN NO EVENT SHALL GEOFF KUENNING OR CONTRIBUTORS BE LIABLE
  34.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  35.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  36.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  37.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  38.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  39.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  40.  * SUCH DAMAGE.
  41.  */
  42.  
  43. /*
  44.  * $Log: ispell.h $
  45.  * Revision 1.67  1995/01/03  19:24:12  geoff
  46.  * Get rid of a non-global declaration.
  47.  *
  48.  * Revision 1.66  1994/12/27  23:08:49  geoff
  49.  * Fix a lot of subtly bad assumptions about the widths of ints and longs
  50.  * which only show up on 64-bit machines like the Cray and the DEC Alpha.
  51.  *
  52.  * Revision 1.65  1994/11/02  06:56:10  geoff
  53.  * Remove the anyword feature, which I've decided is a bad idea.
  54.  *
  55.  * Revision 1.64  1994/10/25  05:46:18  geoff
  56.  * Add the FF_ANYWORD flag for defining an affix that will apply to any
  57.  * word, even if not explicitly specified.  (Good for French.)
  58.  *
  59.  * Revision 1.63  1994/09/16  04:48:28  geoff
  60.  * Make stringdups and laststringch unsigned ints, and dupnos a plain
  61.  * int, so that we can handle more than 128 stringchars and stringchar
  62.  * types.
  63.  *
  64.  * Revision 1.62  1994/09/01  06:06:39  geoff
  65.  * Change erasechar/killchar to uerasechar/ukillchar to avoid
  66.  * shared-library problems on HP systems.
  67.  *
  68.  * Revision 1.61  1994/08/31  05:58:35  geoff
  69.  * Add contextoffset, used in -a mode to handle extremely long lines.
  70.  *
  71.  * Revision 1.60  1994/05/17  06:44:15  geoff
  72.  * Add support for controlled compound formation and the COMPOUNDONLY
  73.  * option to affix flags.
  74.  *
  75.  * Revision 1.59  1994/03/15  06:25:16  geoff
  76.  * Change deftflag's initialization so we can tell if -t/-n appeared.
  77.  *
  78.  * Revision 1.58  1994/02/07  05:53:28  geoff
  79.  * Add typecasts to the the 7-bit versions of ichar* routines
  80.  *
  81.  * Revision 1.57  1994/01/25  07:11:48  geoff
  82.  * Get rid of all old RCS log lines in preparation for the 3.1 release.
  83.  *
  84.  */
  85.  
  86. #include <stdio.h>
  87.  
  88. #ifdef __STDC__
  89. #define P(x)    x
  90. #define VOID    void
  91. #else /* __STDC__ */
  92. #define P(x)    ()
  93. #define VOID    char
  94. #define const
  95. #endif /* __STDC__ */
  96.  
  97. #ifdef NO8BIT
  98. #define SET_SIZE    128
  99. #else
  100. #define SET_SIZE    256
  101. #endif
  102.  
  103. #ifdef AMIGA
  104. #include <proto/exec.h>
  105. #include <proto/rexxsyslib.h>
  106. #include "minrexx.h"
  107. #endif /* AMIGA */
  108.  
  109. #define MASKSIZE    (MASKBITS / MASKTYPE_WIDTH)
  110.  
  111. #ifdef lint
  112. extern void    SETMASKBIT P ((MASKTYPE * mask, int bit));
  113. extern void    CLRMASKBIT P ((MASKTYPE * mask, int bit));
  114. extern int    TSTMASKBIT P ((MASKTYPE * mask, int bit));
  115. #else /* lint */
  116. /* The following is really testing for MASKSIZE <= 1, but cpp can't do that */
  117. #if MASKBITS <= MASKTYPE_WIDTH
  118. #define SETMASKBIT(mask, bit) ((mask)[0] |= (MASKTYPE) 1 << (bit))
  119. #define CLRMASKBIT(mask, bit) ((mask)[0] &= (MASKTYPE) ~(1 << (bit)))
  120. #define TSTMASKBIT(mask, bit) ((mask)[0] & ((MASKTYPE) 1 << (bit)))
  121. #else
  122. #define SETMASKBIT(mask, bit) \
  123.             ((mask)[(bit) / MASKTYPE_WIDTH] |= \
  124.               (MASKTYPE) 1 << ((bit) & (MASKTYPE_WIDTH - 1)))
  125. #define CLRMASKBIT(mask, bit) \
  126.             ((mask)[(bit) / MASKTYPE_WIDTH] &= \
  127.               ~((MASKTYPE) 1 << ((bit) & (MASKTYPE_WIDTH - 1))))
  128. #define TSTMASKBIT(mask, bit) \
  129.             ((mask)[(bit) / MASKTYPE_WIDTH] & \
  130.               ((MASKTYPE) 1 << ((bit) & (MASKTYPE_WIDTH - 1))))
  131. #endif
  132. #endif /* lint */
  133.  
  134. #if MASKBITS > 64
  135. #define FULLMASKSET
  136. #endif
  137.  
  138. #ifdef lint
  139. extern int    BITTOCHAR P ((int bit));
  140. extern int    CHARTOBIT P ((int ch));
  141. #endif /* lint */
  142.  
  143. #if MASKBITS <= 32
  144. # ifndef lint
  145. #define BITTOCHAR(bit)    ((bit) + 'A')
  146. #define CHARTOBIT(ch)    ((ch) - 'A')
  147. # endif /* lint */
  148. #define LARGESTFLAG    26    /* 5 are needed for flagfield below */
  149. #define FLAGBASE    (MASKTYPE_WIDTH - 6)
  150. #else
  151. # if MASKBITS <= 64
  152. #  ifndef lint
  153. #define BITTOCHAR(bit)    ((bit) + 'A')
  154. #define CHARTOBIT(ch)    ((ch) - 'A')
  155. #  endif /* lint */
  156. #define LARGESTFLAG    (64 - 6) /* 5 are needed for flagfield below */
  157. #define FLAGBASE    (MASKTYPE_WIDTH - 6)
  158. # else
  159. #  ifndef lint
  160. #define BITTOCHAR(bit)    (bit)
  161. #define CHARTOBIT(ch)    (ch)
  162. #  endif /* lint */
  163. #define LARGESTFLAG    MASKBITS /* flagfield is a separate field */
  164. #define FLAGBASE    0
  165. # endif
  166. #endif
  167.  
  168. /*
  169. ** Data type for internal word storage.  If necessary, we use shorts rather
  170. ** than chars so that string characters can be encoded as a single unit.
  171. */
  172. #if (SET_SIZE + MAXSTRINGCHARS) <= 256
  173. #ifndef lint
  174. #define ICHAR_IS_CHAR
  175. #endif /* lint */
  176. #endif
  177.  
  178. #ifdef ICHAR_IS_CHAR
  179. typedef unsigned char    ichar_t;    /* Internal character */
  180. #define icharlen(s)    strlen ((char *) s)
  181. #define icharcpy(a, b)    strcpy ((char *) a, (char *) b)
  182. #define icharcmp(a, b)    strcmp ((char *) a, (char *) b)
  183. #define icharncmp(a, b, n) strncmp ((char *) a, (char *) b, n)
  184. #define chartoichar(x)    ((ichar_t) (x))
  185. #else
  186. typedef unsigned short    ichar_t;    /* Internal character */
  187. #define chartoichar(x)    ((ichar_t) (unsigned char) (x))
  188. #endif
  189.  
  190. struct dent
  191.     {
  192.     struct dent *    next;
  193.     char *        word;
  194.     MASKTYPE        mask[MASKSIZE];
  195. #ifdef FULLMASKSET
  196.     char        flags;
  197. #endif
  198.     };
  199.  
  200. /*
  201. ** Flags in the directory entry.  If FULLMASKSET is undefined, these are
  202. ** stored in the highest bits of the last longword of the mask field.  If
  203. ** FULLMASKSET is defined, they are stored in the extra "flags" field.
  204. #ifndef NO_CAPITALIZATION_SUPPORT
  205. **
  206. ** If a word has only one capitalization form, and that form is not
  207. ** FOLLOWCASE, it will have exactly one entry in the dictionary.  The
  208. ** legal capitalizations will be indicated by the 2-bit capitalization
  209. ** field, as follows:
  210. **
  211. **    ALLCAPS        The word must appear in all capitals.
  212. **    CAPITALIZED    The word must be capitalized (e.g., London).
  213. **            It will also be accepted in all capitals.
  214. **    ANYCASE        The word may appear in lowercase, capitalized,
  215. **            or all-capitals.
  216. **
  217. ** Regardless of the capitalization flags, the "word" field of the entry
  218. ** will point to an all-uppercase copy of the word.  This is to simplify
  219. ** the large portion of the code that doesn't care about capitalization.
  220. ** Ispell will generate the correct version when needed.
  221. **
  222. ** If a word has more than one capitalization, there will be multiple
  223. ** entries for it, linked together by the "next" field.  The initial
  224. ** entry for such words will be a dummy entry, primarily for use by code
  225. ** that ignores capitalization.  The "word" field of this entry will
  226. ** again point to an all-uppercase copy of the word.  The "mask" field
  227. ** will contain the logical OR of the mask fields of all variants.
  228. ** A header entry is indicated by a capitalization type of ALLCAPS,
  229. ** with the MOREVARIANTS bit set.
  230. **
  231. ** The following entries will define the individual variants.  Each
  232. ** entry except the last has the MOREVARIANTS flag set, and each
  233. ** contains one of the following capitalization options:
  234. **
  235. **    ALLCAPS        The word must appear in all capitals.
  236. **    CAPITALIZED    The word must be capitalized (e.g., London).
  237. **            It will also be accepted in all capitals.
  238. **    FOLLOWCASE    The word must be capitalized exactly like the
  239. **            sample in the entry.  Prefix (suffix) characters
  240. **            must be rendered in the case of the first (last)
  241. **            "alphabetic" character.  It will also be accepted
  242. **            in all capitals.  ("Alphabetic" means "mentioned
  243. **            in a 'casechars' statement".)
  244. **    ANYCASE        The word may appear in lowercase, capitalized,
  245. **            or all-capitals.
  246. **
  247. ** The "mask" field for the entry contains only the affix flag bits that
  248. ** are legal for that capitalization.  The "word" field will be null
  249. ** except for FOLLOWCASE entries, where it will point to the
  250. ** correctly-capitalized spelling of the root word.
  251. **
  252. ** It is worth discussing why the ALLCAPS option is used in
  253. ** the header entry.  The header entry accepts an all-capitals
  254. ** version of the root plus every affix (this is always legal, since
  255. ** words get capitalized in headers and so forth).  Further, all of
  256. ** the following variant entries will reject any all-capitals form
  257. ** that is illegal due to an affix.
  258. **
  259. ** Finally, note that variations in the KEEP flag can cause a multiple-variant
  260. ** entry as well.  For example, if the personal dictionary contains "ALPHA",
  261. ** (KEEP flag set) and the user adds "alpha" with the KEEP flag clear, a
  262. ** multiple-variant entry will be created so that "alpha" will be accepted
  263. ** but only "ALPHA" will actually be kept.
  264. #endif
  265. */
  266. #ifdef FULLMASKSET
  267. #define flagfield    flags
  268. #else
  269. #define flagfield    mask[MASKSIZE - 1]
  270. #endif
  271. #define USED        ((MASKTYPE) 1 << (FLAGBASE + 0))
  272. #define KEEP        ((MASKTYPE) 1 << (FLAGBASE + 1))
  273. #ifdef NO_CAPITALIZATION_SUPPORT
  274. #define ALLFLAGS    (USED | KEEP)
  275. #else /* NO_CAPITALIZATION_SUPPORT */
  276. #define ANYCASE        ((MASKTYPE) 0 << (FLAGBASE + 2))
  277. #define ALLCAPS        ((MASKTYPE) 1 << (FLAGBASE + 2))
  278. #define CAPITALIZED    ((MASKTYPE) 2 << (FLAGBASE + 2))
  279. #define FOLLOWCASE    ((MASKTYPE) 3 << (FLAGBASE + 2))
  280. #define CAPTYPEMASK    ((MASKTYPE) 3 << (FLAGBASE + 2))
  281. #define MOREVARIANTS    ((MASKTYPE) 1 << (FLAGBASE + 4))
  282. #define ALLFLAGS    (USED | KEEP | CAPTYPEMASK | MOREVARIANTS)
  283. #define captype(x)    ((x) & CAPTYPEMASK)
  284. #endif /* NO_CAPITALIZATION_SUPPORT */
  285.  
  286. /*
  287.  * Language tables used to encode prefix and suffix information.
  288.  */
  289. struct flagent
  290.     {
  291.     ichar_t *        strip;            /* String to strip off */
  292.     ichar_t *        affix;            /* Affix to append */
  293.     short        flagbit;        /* Flag bit this ent matches */
  294.     short        stripl;            /* Length of strip */
  295.     short        affl;            /* Length of affix */
  296.     short        numconds;        /* Number of char conditions */
  297.     short        flagflags;        /* Modifiers on this flag */
  298.     char        conds[SET_SIZE + MAXSTRINGCHARS]; /* Adj. char conds */
  299.     };
  300.  
  301. /*
  302.  * Bits in flagflags
  303.  */
  304. #define FF_CROSSPRODUCT    (1 << 0)        /* Affix does cross-products */
  305. #define FF_COMPOUNDONLY    (1 << 1)        /* Afx works in compounds */
  306.  
  307. union ptr_union                    /* Aid for building flg ptrs */
  308.     {
  309.     struct flagptr *    fp;            /* Pointer to more indexing */
  310.     struct flagent *    ent;            /* First of a list of ents */
  311.     };
  312.  
  313. struct flagptr
  314.     {
  315.     union ptr_union    pu;            /* Ent list or more indexes */
  316.     int            numents;        /* If zero, pu.fp is valid */
  317.     };
  318.  
  319. /*
  320.  * Description of a single string character type.
  321.  */
  322. struct strchartype
  323.     {
  324.     char *        name;            /* Name of the type */
  325.     char *        deformatter;        /* Deformatter to use */
  326.     char *        suffixes;        /* File suffixes, null seps */
  327.     };
  328.  
  329. /*
  330.  * Header placed at the beginning of the hash file.
  331.  */
  332. struct hashheader
  333.     {
  334.     unsigned short magic;                        /* Magic number for ID */
  335.     unsigned short compileoptions;        /* How we were compiled */
  336.     short maxstringchars;            /* Max # strchrs we support */
  337.     short maxstringcharlen;            /* Max strchr len supported */
  338.     short compoundmin;                /* Min lth of compound parts */
  339.     short compoundbit;                /* Flag 4 compounding roots */
  340.     int stringsize;                /* Size of string table */
  341.     int lstringsize;                /* Size of lang. str tbl */
  342.     int tblsize;                /* No. entries in hash tbl */
  343.     int stblsize;                /* No. entries in sfx tbl */
  344.     int ptblsize;                /* No. entries in pfx tbl */
  345.     int sortval;                /* Largest sort ID assigned */
  346.     int nstrchars;                /* No. strchars defined */
  347.     int nstrchartype;                /* No. strchar types */
  348.     int strtypestart;                /* Start of strtype table */
  349.     char nrchars[5];                /* Nroff special characters */
  350.     char texchars[13];                /* TeX special characters */
  351.     char compoundflag;                /* Compund-word handling */
  352.     char defhardflag;                /* Default tryveryhard flag */
  353.     char flagmarker;                /* "Start-of-flags" char */
  354.     unsigned short sortorder[SET_SIZE + MAXSTRINGCHARS]; /* Sort ordering */
  355.     ichar_t lowerconv[SET_SIZE + MAXSTRINGCHARS]; /* Lower-conversion table */
  356.     ichar_t upperconv[SET_SIZE + MAXSTRINGCHARS]; /* Upper-conversion table */
  357.     char wordchars[SET_SIZE + MAXSTRINGCHARS]; /* NZ for chars found in wrds */
  358.     char upperchars[SET_SIZE + MAXSTRINGCHARS]; /* NZ for uppercase chars */
  359.     char lowerchars[SET_SIZE + MAXSTRINGCHARS]; /* NZ for lowercase chars */
  360.     char boundarychars[SET_SIZE + MAXSTRINGCHARS]; /* NZ for boundary chars */
  361.     char stringstarts[SET_SIZE];        /* NZ if char can start str */
  362.     char stringchars[MAXSTRINGCHARS][MAXSTRINGCHARLEN + 1]; /* String chars */
  363.     unsigned int stringdups[MAXSTRINGCHARS];    /* No. of "base" char */
  364.     int dupnos[MAXSTRINGCHARS];            /* Dup char ID # */
  365.     unsigned short magic2;            /* Second magic for dbl chk */
  366.     };
  367.  
  368. /* hash table magic number */
  369. #define MAGIC            0x9602
  370.  
  371. /* compile options, put in the hash header for consistency checking */
  372. #ifdef NO8BIT
  373. # define MAGIC8BIT        0x01
  374. #else
  375. # define MAGIC8BIT        0x00
  376. #endif
  377. #ifdef NO_CAPITALIZATION_SUPPORT
  378. # define MAGICCAPITALIZATION    0x00
  379. #else
  380. # define MAGICCAPITALIZATION    0x02
  381. #endif
  382. #if MASKBITS <= 32
  383. # define MAGICMASKSET        0x00
  384. #else
  385. # if MASKBITS <= 64
  386. #  define MAGICMASKSET        0x04
  387. # else
  388. #  if MASKBITS <= 128
  389. #   define MAGICMASKSET        0x08
  390. #  else
  391. #   define MAGICMASKSET        0x0C
  392. #  endif
  393. # endif
  394. #endif
  395.  
  396. #define COMPILEOPTIONS    (MAGIC8BIT | MAGICCAPITALIZATION | MAGICMASKSET)
  397.  
  398. /*
  399.  * Structure used to record data about successful lookups; these values
  400.  * are used in the ins_root_cap routine to produce correct capitalizations.
  401.  */
  402. struct success
  403.     {
  404.     struct dent *    dictent;    /* Header of dict entry chain for wd */
  405.     struct flagent *    prefix;        /* Prefix flag used, or NULL */
  406.     struct flagent *    suffix;        /* Suffix flag used, or NULL */
  407.     };
  408.  
  409. /*
  410. ** Offsets into the nroff special-character array
  411. */
  412. #define NRLEFTPAREN    hashheader.nrchars[0]
  413. #define NRRIGHTPAREN    hashheader.nrchars[1]
  414. #define NRDOT        hashheader.nrchars[2]
  415. #define NRBACKSLASH    hashheader.nrchars[3]
  416. #define NRSTAR        hashheader.nrchars[4]
  417.  
  418. /*
  419. ** Offsets into the TeX special-character array
  420. */
  421. #define TEXLEFTPAREN    hashheader.texchars[0]
  422. #define TEXRIGHTPAREN    hashheader.texchars[1]
  423. #define TEXLEFTSQUARE    hashheader.texchars[2]
  424. #define TEXRIGHTSQUARE    hashheader.texchars[3]
  425. #define TEXLEFTCURLY    hashheader.texchars[4]
  426. #define TEXRIGHTCURLY    hashheader.texchars[5]
  427. #define TEXLEFTANGLE    hashheader.texchars[6]
  428. #define TEXRIGHTANGLE    hashheader.texchars[7]
  429. #define TEXBACKSLASH    hashheader.texchars[8]
  430. #define TEXDOLLAR    hashheader.texchars[9]
  431. #define TEXSTAR        hashheader.texchars[10]
  432. #define TEXDOT        hashheader.texchars[11]
  433. #define TEXPERCENT    hashheader.texchars[12]
  434.  
  435. /*
  436. ** Values for compoundflag
  437. */
  438. #define COMPOUND_NEVER        0    /* Compound words are never good */
  439. #define COMPOUND_ANYTIME    1    /* Accept run-together words */
  440. #define COMPOUND_CONTROLLED    2    /* Compounds controlled by afx flags */
  441.  
  442. /*
  443. ** The isXXXX macros normally only check ASCII range, and don't support
  444. ** the character sets of other languages.  These private versions handle
  445. ** whatever character sets have been defined in the affix files.
  446. */
  447. #ifdef lint
  448. extern int    myupper P ((unsigned int ch));
  449. extern int    mylower P ((unsigned int ch));
  450. extern int    myspace P ((unsigned int ch));
  451. extern int    iswordch P ((unsigned int ch));
  452. extern int    isboundarych P ((unsigned int ch));
  453. extern int    isstringstart P ((unsigned int ch));
  454. extern ichar_t    mytolower P ((unsigned int ch));
  455. extern ichar_t    mytoupper P ((unsigned int ch));
  456. #else /* lint */
  457. #define myupper(X)    (hashheader.upperchars[X])
  458. #define mylower(X)    (hashheader.lowerchars[X])
  459. #define myspace(X)    (((X) > 0)  &&  ((X) < 0x80) \
  460.               &&  isspace((unsigned char) (X)))
  461. #define iswordch(X)    (hashheader.wordchars[X])
  462. #define isboundarych(X) (hashheader.boundarychars[X])
  463. #define isstringstart(X) (hashheader.stringstarts[(unsigned char) (X)])
  464. #define mytolower(X)    (hashheader.lowerconv[X])
  465. #define mytoupper(X)    (hashheader.upperconv[X])
  466. #endif /* lint */
  467.  
  468. /*
  469. ** These macros are similar to the ones above, but they take into account
  470. ** the possibility of string characters.  Note well that they take a POINTER,
  471. ** not a character.
  472. **
  473. ** The "l_" versions set "len" to the length of the string character as a
  474. ** handy side effect.  (Note that the global "laststringch" is also set,
  475. ** and sometimes used, by these macros.)
  476. **
  477. ** The "l1_" versions go one step further and guarantee that the "len"
  478. ** field is valid for *all* characters, being set to 1 even if the macro
  479. ** returns false.  This macro is a great example of how NOT to write
  480. ** readable C.
  481. */
  482. #define isstringch(ptr, canon)    (isstringstart (*ptr) \
  483.                   &&  stringcharlen (ptr, canon) > 0)
  484. #define l_isstringch(ptr, len, canon)    \
  485.                 (isstringstart (*ptr) \
  486.                   &&  (len = stringcharlen (ptr, canon)) > 0)
  487. #define l1_isstringch(ptr, len, canon)    \
  488.                 (len = 1, \
  489.                   isstringstart (*ptr) \
  490.                     &&  ((len = stringcharlen (ptr, canon)) \
  491.                     > 0 \
  492.                       ? 1 : (len = 1, 0)))
  493.  
  494. /*
  495.  * Sizes of buffers returned by ichartosstr/strtosichar.
  496.  */
  497. #define ICHARTOSSTR_SIZE (INPUTWORDLEN + 4 * MAXAFFIXLEN + 4)
  498. #define STRTOSICHAR_SIZE ((INPUTWORDLEN + 4 * MAXAFFIXLEN + 4) \
  499.               * sizeof (ichar_t))
  500.  
  501. /*
  502.  * termcap variables
  503.  */
  504. #ifdef MAIN
  505. # define EXTERN /* nothing */
  506. #else
  507. # define EXTERN extern
  508. #endif
  509.  
  510. EXTERN char *    BC;    /* backspace if not ^H */
  511. EXTERN char *    cd;    /* clear to end of display */
  512. EXTERN char *    cl;    /* clear display */
  513. EXTERN char *    cm;    /* cursor movement */
  514. EXTERN char *    ho;    /* home */
  515. EXTERN char *    nd;    /* non-destructive space */
  516. EXTERN char *    so;    /* standout */
  517. EXTERN char *    se;    /* standout end */
  518. EXTERN int    sg;    /* space taken by so/se */
  519. EXTERN char *    ti;    /* terminal initialization sequence */
  520. EXTERN char *    te;    /* terminal termination sequence */
  521. EXTERN int    li;    /* lines */
  522. EXTERN int    co;    /* columns */
  523.  
  524. EXTERN int    contextsize;    /* number of lines of context to show */
  525. EXTERN char    contextbufs[MAXCONTEXT][BUFSIZ]; /* Context of current line */
  526. EXTERN int    contextoffset;    /* Offset of line start in contextbufs[0] */
  527. EXTERN char *    currentchar;    /* Location in contextbufs */
  528. EXTERN char    ctoken[INPUTWORDLEN + MAXAFFIXLEN]; /* Current token as char */
  529. EXTERN ichar_t    itoken[INPUTWORDLEN + MAXAFFIXLEN]; /* Ctoken as ichar_t str */
  530.  
  531. EXTERN char    termcap[2048];    /* termcap entry */
  532. EXTERN char    termstr[2048];    /* for string values */
  533. EXTERN char *    termptr;    /* pointer into termcap, used by tgetstr */
  534.  
  535. EXTERN int    numhits;    /* number of hits in dictionary lookups */
  536. EXTERN struct success
  537.         hits[MAX_HITS]; /* table of hits gotten in lookup */
  538.  
  539. EXTERN char *    hashstrings;    /* Strings in hash table */
  540. EXTERN struct hashheader
  541.         hashheader;    /* Header of hash table */
  542. EXTERN struct dent *
  543.         hashtbl;    /* Main hash table, for dictionary */
  544. EXTERN int    hashsize;    /* Size of main hash table */
  545.  
  546. EXTERN char    hashname[MAXPATHLEN]; /* Name of hash table file */
  547.  
  548. EXTERN int    aflag;        /* NZ if -a or -A option specified */
  549. EXTERN int    cflag;        /* NZ if -c (crunch) option */
  550. EXTERN int    lflag;        /* NZ if -l (list) option */
  551. EXTERN int    incfileflag;    /* whether xgets() acts exactly like gets() */
  552. EXTERN int    nodictflag;    /* NZ if dictionary not needed */
  553. #ifdef AMIGA
  554. EXTERN int    rflag;        /* NZ if -r option specified */
  555. #endif /* AMIGA */
  556.  
  557. EXTERN int    uerasechar;    /* User's erase character, from stty */
  558. EXTERN int    ukillchar;    /* User's kill character */
  559.  
  560. EXTERN unsigned int laststringch; /* Number of last string character */
  561. EXTERN int    defdupchar;    /* Default duplicate string type */
  562.  
  563. EXTERN int    numpflags;        /* Number of prefix flags in table */
  564. EXTERN int    numsflags;        /* Number of suffix flags in table */
  565. EXTERN struct flagptr pflagindex[SET_SIZE + MAXSTRINGCHARS];
  566.                     /* Fast index to pflaglist */
  567. EXTERN struct flagent *    pflaglist;    /* Prefix flag control list */
  568. EXTERN struct flagptr sflagindex[SET_SIZE + MAXSTRINGCHARS];
  569.                     /* Fast index to sflaglist */
  570. EXTERN struct flagent *    sflaglist;    /* Suffix flag control list */
  571.  
  572. EXTERN struct strchartype *        /* String character type collection */
  573.         chartypes;
  574.  
  575. EXTERN FILE *    infile;            /* File being corrected */
  576. EXTERN FILE *    outfile;        /* Corrected copy of infile */
  577.  
  578. EXTERN char *    askfilename;        /* File specified in -f option */
  579.  
  580. EXTERN int    changes;        /* NZ if changes made to cur. file */
  581. EXTERN int    readonly;        /* NZ if current file is readonly */
  582. EXTERN int    quit;            /* NZ if we're done with this file */
  583.  
  584. #define MAXPOSSIBLE    100    /* Max no. of possibilities to generate */
  585.  
  586. EXTERN char    possibilities[MAXPOSSIBLE][INPUTWORDLEN + MAXAFFIXLEN];
  587.                 /* Table of possible corrections */
  588. EXTERN int    pcount;        /* Count of possibilities generated */
  589. EXTERN int    maxposslen;    /* Length of longest possibility */
  590. EXTERN int    easypossibilities; /* Number of "easy" corrections found */
  591.                 /* ..(defined as those using legal affixes) */
  592.  
  593. /*
  594.  * The following array contains a list of characters that should be tried
  595.  * in "missingletter."  Note that lowercase characters are omitted.
  596.  */
  597. EXTERN int    Trynum;        /* Size of "Try" array */
  598. EXTERN ichar_t    Try[SET_SIZE + MAXSTRINGCHARS];
  599.  
  600. /*
  601.  * Initialized variables.  These are generated using macros so that they
  602.  * may be consistently declared in all programs.  Numerous examples of
  603.  * usage are given below.
  604.  */
  605. #ifdef MAIN
  606. #define INIT(decl, init)    decl = init
  607. #else
  608. #define INIT(decl, init)    extern decl
  609. #endif
  610.  
  611. #ifdef MINIMENU
  612. INIT (int minimenusize, 2);        /* MUST be either 2 or zero */
  613. #else /* MINIMENU */
  614. INIT (int minimenusize, 0);        /* MUST be either 2 or zero */
  615. #endif /* MINIMENU */
  616.  
  617. INIT (int eflag, 0);            /* NZ for expand mode */
  618. INIT (int dumpflag, 0);            /* NZ to do dump mode */
  619. INIT (int fflag, 0);            /* NZ if -f specified */
  620. #ifndef USG
  621. INIT (int sflag, 0);            /* NZ to stop self after EOF */
  622. #endif
  623. INIT (int vflag, 0);            /* NZ to display characters as M-xxx */
  624. INIT (int xflag, DEFNOBACKUPFLAG);    /* NZ to suppress backups */
  625. INIT (int deftflag, -1);        /* NZ for TeX mode by default */
  626. INIT (int tflag, DEFTEXFLAG);        /* NZ for TeX mode in current file */
  627. INIT (int prefstringchar, -1);        /* Preferred string character type */
  628.  
  629. INIT (int terse, 0);            /* NZ for "terse" mode */
  630.  
  631. INIT (char tempfile[MAXPATHLEN], "");    /* Name of file we're spelling into */
  632.  
  633. INIT (int minword, MINWORD);        /* Longest always-legal word */
  634. INIT (int sortit, 1);            /* Sort suggestions alphabetically */
  635. INIT (int compoundflag, -1);        /* How to treat compounds: see above */
  636. INIT (int tryhardflag, -1);        /* Always call tryveryhard */
  637.  
  638. INIT (char * currentfile, NULL);    /* Name of current input file */
  639.  
  640. /* Odd numbers for math mode in LaTeX; even for LR or paragraph mode */
  641. INIT (int math_mode, 0);
  642. /* P -- paragraph or LR mode
  643.  * b -- parsing a \begin statement
  644.  * e -- parsing an \end statement
  645.  * r -- parsing a \ref type of argument.
  646.  * m -- looking for a \begin{minipage} argument.
  647.  */
  648. INIT (char LaTeX_Mode, 'P');
  649.